package com.hxexp.weixin.common.config;

import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

/**
 * HPE微信接口URL配置
 *
 * @author li.jiang
 *
 */
public final class HpeApiURLConfig {
    // URL格式字符串
    private static final String URL_FORMAT = "http://%s:%s/%s/%s";
    // URL映射
    private static final ConcurrentMap<String, String> URL_MAP = new ConcurrentHashMap<String, String>();
    // 主机域名或IP地址
    private String host;
    // 端口号
    private String port;
    // 上下文名称
    private String context;

    /**
     * @return the host
     */
    public String getHost() {
        return host;
    }

    /**
     * @param host
     *            the host to set
     */
    public void setHost(String host) {
        this.host = host;
    }

    /**
     * @return the port
     */
    public String getPort() {
        return port;
    }

    /**
     * @param port
     *            the port to set
     */
    public void setPort(String port) {
        this.port = port;
    }

    /**
     * @return the context
     */
    public String getContext() {
        return context;
    }

    /**
     * @param context
     *            the context to set
     */
    public void setContext(String context) {
        this.context = context;
    }

    /**
     * 得到完整的接口地址
     *
     * @param uri
     *            接口URI
     * @return 接口URL
     */
    public String getURL(String uri) {
        String url = URL_MAP.get(uri);
        if (url == null) {
            url = String.format(URL_FORMAT, host, port, context, uri);
            URL_MAP.put(uri, url);
        }

        return url;
    }
}
